import dt from '@dt/dt'
import { defineStore } from 'pinia'

const key_user = 'user_info'

export const userStore = defineStore('user', {
  state: () => {
    return {
      info: dt.storage.get(key_user)
    }
  },
  getters: {
    isLogin: (state) => {
      return state.info
    }
  },
  actions: {
    login(item) {
      this.info = item
      dt.storage.set(key_user, item)
    },

    logout() {
      this.info = null
      dt.storage.remove(key_user)
    }
  }
})
